package com.ticket.sass.admin.controller;


import com.github.xiaoymin.knife4j.annotations.ApiSupport;
import com.ticket.sass.admin.annotation.Loggable;
import com.ticket.sass.admin.annotation.Module;
import com.ticket.sass.admin.business.CinemaConfigBusiness;
import com.ticket.sass.admin.dto.input.config.*;
import com.ticket.sass.admin.dto.output.TicketCheckConfigOutput;
import com.ticket.sass.admin.dto.output.config.*;
import com.ticket.sass.admin.model.ResultModel;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;


/**
 * 影院控制层
 * @author ywb
 * @date 2021-11-25 14:44
 */
@RestController
@Api(tags = {"影院配置-模块"})
@ApiSupport(order = 10)
@RequestMapping("/cinema-configs")
public class CinemaConfigController {

    final CinemaConfigBusiness business;
    
    public CinemaConfigController(CinemaConfigBusiness cinemaConfigBusiness) {
        this.business = cinemaConfigBusiness;
    }
    
    @GetMapping("/wxa-config")
    @ApiOperation("获取小程序设置")
    public ResultModel<WxaConfigOutput> getWxaConfig() {
        WxaConfigOutput output = business.wxaConfig();
        return ResultModel.success(output);
    }
    
    @PutMapping("/wxa-config")
    @ApiOperation("修改小程序设置")
    @Loggable(module = Module.CONFIG, desc = "修改小程序设置")
    public ResultModel<String> wxaConfig(
        @RequestBody @Valid WxaConfigInput input
    ) {
        business.updWxaConfig(input);
        return ResultModel.success();
    }
    
    @GetMapping("/service-charge")
    @ApiOperation("获取服务费设置")
    public ResultModel<ServiceChargeOutput> serviceCharge() {
        ServiceChargeOutput output = business.serviceCharge();
        return ResultModel.success(output);
    }
    
    @PutMapping("/service-charge")
    @ApiOperation("修改服务费设置")
    @Loggable(module = Module.CONFIG, desc = "修改小程序设置")
    public ResultModel<String> updServiceCharge(
        @RequestBody @Valid ServiceChargeInput input
    ) {
        business.updServiceCharge(input);
        return ResultModel.success();
    }
    
    @GetMapping("/ticket-refund-configs")
    @ApiOperation("获取退改签设置")
    public ResultModel<TicketRefundConfigOutput> getTicketRefundConfigs(
        @Valid TicketRefundTypeInput input
    ) {
        return ResultModel.success(business.ticketRefundConfig(input));
    }
    
    @ApiOperation("修改退改签配置")
    @PutMapping("/ticket-refund-configs")
    @Loggable(module = Module.CONFIG, desc = "修改退改签配置")
    public ResultModel<String> ticketRefundConfigs(
        @RequestBody @Valid TicketRefundConfigInput input
    ) {
        business.updTicketRefundConfig(input);
        return ResultModel.success();
    }

    @GetMapping("/info")
    @ApiOperation("获取影院信息")
    public ResultModel<CinemaConfigOutput> cinemaConfig() {
        CinemaConfigOutput output = business.cinemaConfig();
        return ResultModel.success(output);
    }
    
    @ApiOperation("修改影院信息")
    @PutMapping("/info")
    @Loggable(module = Module.CONFIG, desc = "修改影院配置")
    public ResultModel<String> updCinemaConfig(
        @RequestBody @Valid CinemaConfigInput input
    ) {
        business.updCinemaConfig(input);
        return ResultModel.success();
    }
    
    @GetMapping("/theme-config")
    @ApiOperation("获取主题配置")
    public ResultModel<ThemeConfigOutput> themeConfig(
    ) {
        return ResultModel.success(business.themeConfig());
    }
    
    @ApiOperation("修改主题配置")
    @PutMapping("/theme-config")
    @Loggable(module = Module.CONFIG, desc = "修改主题配置")
    public ResultModel<String> updThemeConfig(
        @RequestBody @Valid ThemeConfigInput input
    ) {
        business.updThemeConfig(input);
        return ResultModel.success();
    }
    
    @GetMapping("/ticket-check")
    @ApiOperation("获取检票配置")
    public ResultModel<TicketCheckConfigOutput> ticketCheckConfig() {
        TicketCheckConfigOutput output = business.ticketCheckConfig();
        return ResultModel.success(output);
    }
    
    @PutMapping("/ticket-check")
    @ApiOperation("修改检票配置")
    @Loggable(module = Module.CONFIG, desc = "修改检票配置")
    public ResultModel<String> updServiceCharge(
        @RequestBody @Valid TicketCheckConfigInput input
    ) {
        business.updTicketCheckConfig(input);
        return ResultModel.success();
    }
    
    @GetMapping("/wx-pay")
    @ApiOperation("获取微信支付配置")
    public ResultModel<WxPayConfigOutput> wxPayConfig() {
        WxPayConfigOutput output = business.wxPayConfig();
        return ResultModel.success(output);
    }
    
    @PutMapping("/wx-pay")
    @ApiOperation("修改微信支付配置")
    @Loggable(module = Module.CONFIG, desc = "修改微信支付配置")
    public ResultModel<String> updWxPayConfig(
         @Valid WxPayConfigInput input
    ) {
        business.updWxPayConfig(input);
        return ResultModel.success();
    }
    
    
    @PutMapping("/cinema-qrcode")
    @ApiOperation("修改影院二维码")
    @Loggable(module = Module.CONFIG, desc = "修改影院二维码")
    public ResultModel<String> setCinemaQrcode(
        @RequestBody @Valid CinemaQrCodeInput input
    ) {
        business. setCinemaQrcode(input);
        return ResultModel.success();
    }
    
    @ApiOperation("获取影院二维码")
    @GetMapping("/cinema-qrcode")
    public ResultModel<CinemaQrCodeOutput> getCinemaQrcode() {
        return ResultModel.success(
            business.getCinemaQrcode()
        );
    }
}
